<template>
	<view>
		<view class="u-demo-wrap" style="background-color: #FFFFFF;">
			<view class="u-demo-area">
				<u-field
					v-model="mobile"
					label="用户名"
					placeholder="请填写用户名"
				>
				</u-field>
				<u-field
					v-model="code"
					label="密码"
					placeholder="请填写密码"
					:password="true"
				>
				</u-field>
				<button type="default" @click="den">登录账号</button>
			</view>
		</view>
	</view>
</template>

<script>
import apiURL from '../../../commer/apiURL'
	export default {
		data() {
			return {
				base:'',
				mobile:'',
				code:''
			}
		},
		onShow(){
			uni.removeStorageSync('chen')
			this.base = apiURL.baseurl
			console.log(this.base)
		},
		methods: {
			den(){
				if(this.mobile == ''|this.code == ''){
					uni.showToast({
						title:'用户名和密码不能为空',
						icon:'none'
					})
					return
				}
				uni.removeStorageSync('token')
				console.log('11')
				console.log(this.base+'/prod-api/api/login')
				this.$post(this.base+'/prod-api/api/login',{
					"username":this.mobile,
					"password":this.code
				}).then((res)=>{
					console.log(res)
					if(res.code == 200){
						uni.setStorage({
							key:'token',
							data:res.token,
							success: (res) => {
								this.$get(this.base+'/prod-api/api/common/user/getInfo').then((res)=>{
									uni.setStorage({
										key:'info',
										data:res.user,
										success: (res) => {
											uni.switchTab({
											url:'/pages/all/index/index'
											})
										}
									})
								})
							},
						})
					}else{
						uni.showToast({
							title:res.msg                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
						})
					}
				})
			}
		}
	}
</script>

<style>

</style>
